package com.photoeditor.demo.model.bean;

import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;

import com.photoeditor.demo.model.bean.stash.ContainerBean;


/**
 * 
 * Emoji面板单个Emoji的Bean
 *
 */
public class EmojiBean implements Parcelable{
	
	/**
	 * 用于记录这个Emoji的Drawable id
	 */
	private int mEmojiId;

	// mPackageName + mName 必须唯一
	/**
	 * 这个Emoji的资源name
	 */
	private String mName;

	/**
	 * 包名
	 */
	private String mPackageName;

	//合成时Emoji显示的宽
	private int mEditEmojiWidth;

	//合成时Emoji显示的高
	private int mEditEmojiHeight;

	private boolean mIsDownloadOnGP;

	private String mCategoryName;

	private String mIconUrl;
	
	/**
	 * 类型
	 */
	private int mType;
	
	public final static int TYPE_RESOURCE = 1;

	public final static int TYPE_INSTALL_EMOJI_APK = 2;

	public final static int TYPE_INSTALL_APK_PACKAGE = 3;

	public final static int TYPE_UNINSTALL_APK_PACKAGE = 4;

	public final static int TYPE_ONLINE = 5;


	/**
	 * 对内置资源的Emoji的初始化
	 * @param emojiId
	 * @param name
	 */
	public EmojiBean(String pkgName, int emojiId, String name, int editEmojiWidth, int editEmojiHeight, String categoryName){
		mEmojiId = emojiId;
		mName = name;
		mType = TYPE_RESOURCE;
		mPackageName = pkgName;
		mEditEmojiWidth = editEmojiWidth;
		mEditEmojiHeight = editEmojiHeight;
		mIsDownloadOnGP = false;
		mCategoryName = categoryName;
	}

	/**
	 * 线上数据使用 只需要一个url即可
	 * @param pkgName
	 * @param type
	 * @param iconUrl
	 * @param editEmojiWidth
	 * @param editEmojiHeight
	 */
	public EmojiBean(String pkgName, int type, String iconUrl, int editEmojiWidth, int editEmojiHeight){
		mPackageName = pkgName;
		mType = type;
		mIconUrl = iconUrl;
		mEditEmojiWidth = editEmojiWidth;
		mEditEmojiHeight = editEmojiHeight;
		mIsDownloadOnGP = false;
	}
	
	/**
	 * 对已经安装Apk  或者 未安装APK 类型的Emoji的初始化
	 * @param apkRes
	 * @param name
	 * @param packageName
	 */
	public EmojiBean(Resources apkRes, String name, String packageName, int type, int editEmojiWidth, int editEmojiHeight, boolean isDownloadOnGP, String categoryName){
		mName = name;
		mType = type;
		mEmojiId = apkRes.getIdentifier(name, "drawable", packageName);
		mPackageName = packageName;
		mEditEmojiWidth = editEmojiWidth;
		mEditEmojiHeight = editEmojiHeight;
		mIsDownloadOnGP = isDownloadOnGP;
		mCategoryName = categoryName;
	}


	protected EmojiBean(Parcel in) {
		mEmojiId = in.readInt();
		mName = in.readString();
		mPackageName = in.readString();
		mEditEmojiWidth = in.readInt();
		mEditEmojiHeight = in.readInt();
		mIsDownloadOnGP = in.readByte() != 0;
		mCategoryName = in.readString();
		mIconUrl = in.readString();
		mType = in.readInt();
		mARType = in.readInt();
	}

	public static final Creator<EmojiBean> CREATOR = new Creator<EmojiBean>() {
		@Override
		public EmojiBean createFromParcel(Parcel in) {
			return new EmojiBean(in);
		}

		@Override
		public EmojiBean[] newArray(int size) {
			return new EmojiBean[size];
		}
	};

	public int getEmojiId() {
		return mEmojiId;
	}

	public void setEmojiId(int emojiId) {
		mEmojiId = emojiId;
	}

	public String getName() {
		return mName;
	}

	public void setName(String name) {
		mName = name;
	}

	public int getType() {
		return mType;
	}

	public void setType(int type) {
		mType = type;
	}

	public String getPackageName() {
		return mPackageName;
	}

	public boolean isType(int type){
		return (mType == type);
	}

	public int getEditEmojiHeight() {
		return mEditEmojiHeight;
	}

	public void setEditEmojiHeight(int mEditEmojiHeight) {
		this.mEditEmojiHeight = mEditEmojiHeight;
	}

	public int getEditEmojiWidth() {
		return mEditEmojiWidth;
	}

	public void setEditEmojiWidth(int mEditEmojiWidth) {
		this.mEditEmojiWidth = mEditEmojiWidth;
	}

	public boolean isDownloadOnGP() {
		return mIsDownloadOnGP;
	}

	public void setDownloadOnGP(boolean downloadOnGP) {
		mIsDownloadOnGP = downloadOnGP;
	}

	public String getCategoryName() {
		return mCategoryName;
	}

	public void setCategoryName(String categoryName) {
		mCategoryName = categoryName;
	}

	public String getIconUrl() {
		return mIconUrl;
	}

	public void setIconUrl(String iconUrl) {
		mIconUrl = iconUrl;
	}

	/**
	 * AR贴纸
	 */

	//标识AR贴纸
	private int mARType = -1;
	public static final int TYPE_AR_TIME_12 = 0;
	public static final int TYPE_AR_TIME_24 = 1;
	public static final int TYPE_AR_TIME_ELECT = 2;
	public static final int TYPE_AR_DATE_WEEK = 3;
	public static final int TYPE_AR_DATE_MONTH = 4;
	public static final int TYPE_AR_LIKE = 5;

	public void setARType(int arType){
		this.mARType = arType;
	}

	public boolean isARType(){
		return mARType == -1 ? false : true;
	}

	public int getARType(){
		return mARType;
	}

	private ContainerBean mContainerBean;

	public ContainerBean getContainerBean(){
		return  mContainerBean;
	}

	public void setContainerBean(ContainerBean containerBean){
		this.mContainerBean = containerBean;
	}


	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel parcel, int i) {
		parcel.writeInt(mEmojiId);
		parcel.writeString(mName);
		parcel.writeString(mPackageName);
		parcel.writeInt(mEditEmojiWidth);
		parcel.writeInt(mEditEmojiHeight);
		parcel.writeByte((byte) (mIsDownloadOnGP ? 1 : 0));
		parcel.writeString(mCategoryName);
		parcel.writeString(mIconUrl);
		parcel.writeInt(mType);
		parcel.writeInt(mARType);
	}
}
